What is eslint-plugin-no-only-tests?
The eslint-plugin-no-only-tests package is an ESLint plugin that helps developers avoid committing tests that are marked as 'only'. This is useful to ensure that all tests are run and none are accidentally skipped during continuous integration or other automated testing processes.
What are eslint-plugin-no-only-tests's main functionalities?
Disallow 'only' in test cases
This feature disallows the use of 'only' in test cases, which can be used to run a single test or a subset of tests. By setting this rule to 'error', any test cases that use 'only' will cause ESLint to throw an error, ensuring that all tests are run.
module.exports = {
"plugins": ["no-only-tests"],
"rules": {
"no-only-tests/no-only-tests": "error"
}
};
Other packages similar to eslint-plugin-no-only-tests
eslint-plugin-jest
eslint-plugin-jest is an ESLint plugin for Jest testing framework. It includes a rule 'jest/no-focused-tests' that disallows the use of 'only' in test cases, similar to eslint-plugin-no-only-tests. However, eslint-plugin-jest offers a broader range of rules and configurations specifically for Jest.
eslint-plugin-mocha
eslint-plugin-mocha is an ESLint plugin for Mocha testing framework. It includes a rule 'mocha/no-exclusive-tests' that disallows the use of 'only' in test cases, similar to eslint-plugin-no-only-tests. This plugin is tailored for Mocha and provides additional rules for Mocha-specific best practices.
eslint-plugin-no-only-tests
ESLint rule for .only
tests in mocha and other JS testing libraries.
Currently matches the following test blocks by default: describe
, it
, context
, tape
, test
, fixture
, serial
.
Designed to prevent you from committing .only
tests to CI, disabling tests for your whole team.
As of v2.3 you can now override the test blocks and focus functions.
Installation
First you'll need to install ESLint then the plugin:
npm install --save-dev eslint eslint-plugin-no-only-tests
yarn add --dev eslint eslint-plugin-no-only-tests
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-no-only-tests
globally.
Usage
Add no-only-tests
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"no-only-tests"
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"no-only-tests/no-only-tests": "error"
}
}
If you use a testing framework that uses an unsupported block name, or a different way of focusing test (something other than .only
) you can specify an array of blocks and focus methods to match in the options.
{
"rules": {
"no-only-tests/no-only-tests": ["error", {"block": ["test", "it", "assert"], "focus": ["only", "focus"]}]
}
}
The above example will catch any uses of test.only
, test.focus
, it.only
, it.focus
, assert.only
and assert.focus
.
This rule supports autofixing only when the fix
option is set to true
to avoid changing runtime code unintentionally when configured in an editor.
{
"rules": {
"no-only-tests/no-only-tests": ["error", {"fix": true}]
}
}
Options
Option | Type | Description |
---|
block | Array<string> | Specify the block names that your testing framework uses. Defaults to ["describe", "it", "context", "test", "tape", "fixture", "serial"] |
focus | Array<string> | Specify the focus scope that your testing framework uses. Defaults to ["only"] |
fix | boolean | Enable this rule to auto-fix violations, useful for a pre-commit hook, not recommended for users with auto-fixing enabled in their editor. Defaults to false |